<template>
  <div class="login">
    <h1>校园活动管理系统</h1>
    <form @submit.prevent="login">
      <div>
        <label>用户名:</label>
        <input v-model="username" type="text" required>
      </div>
      <div>
        <label>密码:</label>
        <input v-model="password" type="password" required>
      </div>
      <button type="submit">登录</button>
    </form>
  </div>
</template>

<script>
import { addRoutes } from '../router/index.js';
export default {
  name: 'Login',
  data() {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    login() {
      const isAdmin = this.username === 'admin';
      const role = isAdmin ? 'admin' : 'student';
      this.$store.commit('setUserRole', role);
      
      addRoutes(role);
      this.$router.push('/');
    }
  }
}
</script>

<style scoped>
.login {
  max-width: 400px;
  margin: 0 auto;
  padding: 20px;
}
input {
  display: block;
  width: 100%;
  margin: 10px 0;
  padding: 8px;
}
button {
  background: #42b983;
  color: white;
  border: none;
  padding: 10px 15px;
  cursor: pointer;
}
</style>